function  chooseProject(){
    var chooseData={
        "projectId":$("#projectId").val(), //项目编码
        "projectName":$("#projectName").val(), //项目名称
        "projectBelongName":$("#projectBelongName").val(),//所属分公司
        "receiverCompanyName":$("#receiverCompanyName").val(),//收货公司名称
        "invoiceCompanyName":$("#invoiceCompanyName").val(),//开票公司名称
    };
    localStorage.setItem("chooseData",JSON.stringify(chooseData));
    layer_show('选择渠道','chooseChannel.html', 1200, 445);
}

function  chooseChanelProject(){
    var CrmData={
        "customerId":$("#customerId").val(), //项目编码
        "customerCode":$("#customerCode").val(), //项目名称
        "customerName":$("#customerName").val(),//所属分公司
        "belongGroupName":$("#belongGroupName").val(),//所属分公司
    };
    localStorage.setItem("CrmData",JSON.stringify(CrmData));
    layer_show('选择渠道','chooseZjChannel.html', 1200, 445);
}

//保存
function pircaladd(){
    console.log(2000)
    /*var zhekou=""
    if($("#zhekou").val()==""){
        zhekou="100"
    }else {
        zhekou=$("#zhekou").val()
    }
    if($("input[name=radio1]:checked").val()==""||$("input[name=radio1]:checked").val()==undefined){
        $.Huimodalalert('请选择基础价！',2000);
        return false;
    }
    if($("#zhekou").val()>299 || $("#zhekou").val()< 80){
        $.Huimodalalert('折扣率应在80%-299%范围内！',2000);
        return false;

    }*/
    /*var isNo = sessionStorage.getItem("isNo");
    if($("input[name=mainCustomers]:checked").val() == 1 && isNo == 1){
        alert("只能有一个主商户");
        return;
    }*/
    if (sessionStorage.getItem("id")!=null){
        $.ajax({
            url:root.dockingplatform.updateSubChannelConfigInfo,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "id":parseInt(sessionStorage.getItem("id")),
                "parentCustomerCode": sessionStorage.getItem("customerCode"),
                "customerCode": $("#customerCode").val(),
                "projectId": $("#projectId").val(),
                "receiverCompanyName": '',
                "invoiceCompanyName": '',
                "customerId": $("#customerId").val(),
                "customerName": $("#customerName").val(),
                "belongGroupName": $("#belongGroupName").val(),
                "projectName": $("#projectName").val(),
                "projectBelongName": $("#projectBelongName").val(),
                "mainCustomers":$("input[name=mainCustomers]:checked").val(),
                "contacts": $('#contacts').val(),
                "telephone": $('#telephone').val(),
                "address": $('#address').val(),
                "status": (sessionStorage.getItem("customerCode") === 'D000000028' || sessionStorage.getItem("customerCode") == 'D000000031' || sessionStorage.getItem("customerCode") == 'D000000030' || sessionStorage.getItem("customerCode") == 'D000000034'|| sessionStorage.getItem("customerCode") == 'D000000035'|| sessionStorage.getItem("customerCode") == 'D000000041'|| sessionStorage.getItem("customerCode") == 'D000000034'|| sessionStorage.getItem("customerCode") == 'D000000033'|| sessionStorage.getItem("customerCode") == 'D000000040') ? 2 : 0
            }),
            success: function (data) {
                console.log(data)
                if(data.errorCode==0){
                    layer.msg("保存成功",{icon: 6,time:2000},function () {
                        setTimeout(function () {
                            if($("input[name=mainCustomers]:checked").val() == 1){
                                $.ajax({
                                    url:root.dockingplatform.addProductDiscount,
                                    cache: false,  //禁用缓存
                                    type: "POST",
                                    dataType:'json',
                                    contentType: "application/json",
                                    data: JSON.stringify({
                                        "customerCode": $("#customerCode").val(),
                                        "channelId": sessionStorage.getItem("customerCode"),
                                    }),
                                    success: function (data) {
                                        if(data.errorCode==0){
                                            showmsg("设置成功",6);
                                        }else {
                                            $.Huimodalalert(data.msg,2000);
                                        }
                                    },
                                    error: function () {
                                        $.Huimodalalert('设置失败！',2000);
                                    }
                                })
                            }else {
                                var index = parent.location.reload();
                                parent.layer.close(index);
                            }
                        })
                    });

                }else {
                    $.Huimodalalert(data.msg,2000);
                }
            },
            error: function () {
                $.Huimodalalert('保存失败！',2000);
            }
        })
    } else {
        $.ajax({
            url:root.dockingplatform.saveSubChannelConfigInfo,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "parentCustomerCode": sessionStorage.getItem("customerCode"),
                "customerCode": $("#customerCode").val(),
                "projectId": $("#projectId").val(),
                "receiverCompanyName": '',
                "invoiceCompanyName": '',
                "customerId": $("#customerId").val(),
                "customerName": $("#customerName").val(),
                "belongGroupName": $("#belongGroupName").val(),
                "projectName": $("#projectName").val(),
                "projectBelongName": $("#projectBelongName").val(),
                "mainCustomers":$("input[name=mainCustomers]:checked").val(),
                "contacts": $('#contacts').val(),
                "telephone": $('#telephone').val(),
                "address": $('#address').val(),
                "status": (sessionStorage.getItem("customerCode") === 'D000000028' || sessionStorage.getItem("customerCode") == 'D000000031' || sessionStorage.getItem("customerCode") == 'D000000030' || sessionStorage.getItem("customerCode") == 'D000000034'|| sessionStorage.getItem("customerCode") == 'D000000035'|| sessionStorage.getItem("customerCode") == 'D000000041'|| sessionStorage.getItem("customerCode") == 'D000000034'|| sessionStorage.getItem("customerCode") == 'D000000033'|| sessionStorage.getItem("customerCode") == 'D000000040') ? 2 : 0
            }),
            success: function (data) {
                if(data.errorCode==0){

                   layer.msg("保存成功",{icon: 6,time:2000},function () {
                            setTimeout(function () {
                    if($("input[name=mainCustomers]:checked").val() == 1){
                        $.ajax({
                            url:root.dockingplatform.addProductDiscount,
                            cache: false,  //禁用缓存
                            type: "POST",
                            dataType:'json',
                            contentType: "application/json",
                            data: JSON.stringify({
                                "customerCode": $("#customerCode").val(),
                                "channelId": sessionStorage.getItem("customerCode"),
                            }),
                            success: function (data) {
                                if(data.errorCode==0){
                                    showmsg("设置成功",6);
                                }else {
                                    $.Huimodalalert(data.msg,2000);
                                }
                            },
                            error: function () {
                                $.Huimodalalert('设置失败！',2000);
                            }
                        })
                    }else {
                        var index = parent.location.reload();
                        parent.layer.close(index);
                    }

                    })
                });
                }else {
                    $.Huimodalalert(data.msg,2000);
                }
            },
            error: function () {
                $.Huimodalalert('保存失败！',2000);
            }
        })
    }
}

// 提示信息
function showmsg(msg,icon){
    layer.msg(msg, {
        icon:icon,
        time: 1000
    },function(){
        if(icon==6){
            var index = parent.location.reload();
            parent.layer.close(index);
        }
    });
}

$('#telephone').bind('blur', function() {
    var phone = $("#telephone").val();
    var message = "";
    var myreg = /^1[3456789]\d{9}$/;             
    if(phone.length > 0) {
        if(phone.length !=11 || !myreg.test(phone)){
            message = "请输入正确格式的手机号码！";
            $('#err-message').text(message);
            $('#err-message').css('color', 'red');
            $('#telephone').val('');
            $('#telephone').css('border-color', 'red');
        }else{
            $('#err-message').text('');
            $('#telephone').css('border-color', '#ccc');
        }
    } else {
        return;
    }
});
